package sip;

/**
 *
 * @author Akanksha Chauhan
 */
public class Battery {
    
    private static double batteryLevel;
    
    public double getBatteryLevel()
    {
        return batteryLevel;
    }
    public void startUsingBattery()
    {      
        int i = 1;
        
        if(checkBatteryLevelEmpty())
        {
            Alarm alarm = new Alarm();
            alarm.setAlarm("Battery Empty");  
        }
        else
        { 
            Timer batteryTimer = new Timer();
            batteryTimer.start();
            while(batteryLevel == 1 )
            {
                if(batteryTimer.getElapsedTimeSecs()== (10000*i))
                {
                     batteryLevel = batteryLevel - 0.25;
                     i++;
                }
            
                if(batteryLevel == 5)
                {
                    Alarm alarm = new Alarm();
                    alarm.setAlarm("Battery Critically Low");
                }
            }
            batteryTimer.stop();
        }
    }
        
            public void setBatteryLevel(double batteryLeft)
            {
                batteryLevel = batteryLeft;
            }
            // TO Do -- should shut down system when battery dies
        
    

        public boolean checkBatteryLevelEmpty()
        {
            if (batteryLevel ==0)
                return true;
            else
                return false;
        }
}